package com.freshmarket.freshmarket.controller;


import com.freshmarket.freshmarket.controller.form.CouponShowForm;
import com.freshmarket.freshmarket.controller.form.UserRegisterForm;
import com.freshmarket.freshmarket.entity.User;
import com.freshmarket.freshmarket.entity.UserCoupon;
import com.freshmarket.freshmarket.service.ICouponService;
import com.freshmarket.freshmarket.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Squirrel
 * @since 2020-09-04
 */
@RestController
@RequestMapping("/freshmarket/coupon")
@Slf4j
public class CouponController {
    @Autowired
    private ICouponService iCouponService;

    /**
     * 直接发放券查询
     */
    @RequestMapping("selectDirect")
    @ResponseBody
    public Result selectDirect(@RequestBody CouponShowForm couponShowForm) throws Exception {
        Result result = iCouponService.selectDirect(couponShowForm);

        return result;
    }

    /*积分兑换查询*/
    @RequestMapping("selectScore")
    @ResponseBody
    public Result selectScore(@RequestBody CouponShowForm couponShowForm) throws Exception {
        Result result = iCouponService.selectScore(couponShowForm);
        return result;
    }

    /**
     * 查询个人优惠券
     *
     * @param couponStatus
     * @return
     * @throws Exception
     */
    @RequestMapping("selectByIdCoupon")
    @ResponseBody
    public Result selectByIdCoupon(String couponStatus, HttpServletRequest request) throws Exception {
        User user = (User) request.getSession().getAttribute("user");
        Result result = iCouponService.selectByIdCoupon(user.getUserId(), couponStatus);
        return result;

    }
    
}

